﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.MODEL.OverOrder;

namespace MINERP.DisjoinProForOutShop.Forms
{
    public partial class FrmOutShopReCheck : Form
    {
        public FrmOutShopReCheck()
        {
            InitializeComponent();
        }
        public FrmOutShopReCheck(List<OverOrderView> listOrderInfo)
        {
            InitializeComponent();
            CurrOrderList = listOrderInfo.Where(p => p.status == "已分堆在格子中").ToList();
            
        }
        List<OverOrderView> CurrOrderList = new List<OverOrderView>();
      
        private void FrmOutShopReCheck_Load(object sender, EventArgs e)
        {
            gridControlProduct.DataSource = CurrOrderList;
            textEditNum.Text = CurrOrderList.Count.ToString();
            textEditShopname.Text = CurrOrderList.FirstOrDefault().OutShopName;
        }

        private void textEditBarCode_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void textEditBarCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (int)Keys.Enter)
            {
                if (textEditBarCode.Text.Trim().Length == 0)
                {
                    return;
                }
                int orderproductid = Convert.ToInt32(textEditBarCode.Text);
                string strOiBarcode=textEditBarCode.Text;
                if (strOiBarcode.Length != 10)
                {
                    strOiBarcode = "2" + string.Format("{0:d9}", Convert.ToInt32(strOiBarcode));
                }
                textEditBarCode.Text = strOiBarcode;
                OverOrderView order = CurrOrderList.FirstOrDefault(p => p.OrderProductCode == strOiBarcode);
                if (order == null)
                {
                    MessageBox.Show("产品不属于该格子", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    order.isCheck = true;
                }
                gridControlProduct.DataSource = CurrOrderList;
                int checkNum = CurrOrderList.Where(p => p.isCheck).Count();
               
                textEditInNum.Text = checkNum.ToString();
                gridControlProduct.RefreshDataSource();
                if (checkNum == CurrOrderList.Count)
                {
                    MessageBox.Show("复检完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                textEditBarCode.Text = "";
            }
        }

        private void gridViewProduct_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                OverOrderView view = (OverOrderView)gridViewProduct.GetRow(e.RowHandle);
                if (view.isCheck)
                {
                    e.Appearance.BackColor = Color.LightGreen;

                }
            }
        }
    }
}
